package Day12;

import java.util.*;

public class Main {
    //小美的数字
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        long l = in.nextLong(), r = in.nextLong();
        long i = (int)Math.sqrt(l);
        if(i * i < l){
            i++;
        }
        long ans = 0;
        for(; i * i <= r; i++){
            long tmp = i * i;
            //System.out.print(tmp + " ");
            if(check1(tmp)){
                //System.out.print(tmp + " ");
                ans++;
            }
        }
        System.out.println(ans);
    }

    private static boolean check1(long num) {
        long tmp = num;
        List<Long> arr = new ArrayList<>();
        while(tmp > 0){
            arr.add(tmp % 10);
            tmp /= 10;
        }
        List<Long> newArr = new ArrayList<>();
        for(int i = arr.size() - 1; i >= 0; i--){
            newArr.add(arr.get(i));
        }
        for(int i = 0; i < newArr.size(); i++){
            if(i % 2 == 0){
                if((i - 1 > 0 && newArr.get(i) < newArr.get(i - 1))
                || (i + 1 < newArr.size() && newArr.get(i) < newArr.get(i + 1))){
                    return false;
                }
            }
        }
        return true;
    }

    //小美的特殊矩阵
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), m = in.nextInt();
        char[][] arr = new char[n][];
        for(int i = 0; i < n; i++){
            arr[i] = in.next().toCharArray();
        }
        long ans = 0;
        for(int i = 0; i < n - 1; i++){
            for(int j = 0; j < m - 1; j++){
                if(check2(arr, i, j)){
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }

    private static boolean check2(char[][] arr, int i, int j) {
        if(arr[i][j] == arr[i][j + 1]
        || arr[i][j] == arr[i + 1][j]
        || arr[i][j] == arr[i+1][j+1]
        || arr[i][j+1] == arr[i+1][j]
        || arr[i][j+1] == arr[i+1][j+1]
        || arr[i+1][j] == arr[i+1][j+1]){
            return false;
        }
        return true;
    }

    //小美的数组合并
    public static void main(String[] args) {

    }
}
